export default {
  beforeRouteEnter(to, from, next) {
    next(vm => {});
  },
  created() {
    this.appKey = this.$route.query.appKey;
    this.token = this.$route.query.token
      ? this.$route.query.token
      : window.sessionStorage.getItem("token");
    if (this.token) {
      this.loginSuccessCallback(this.token);
    }
  },
  data() {
    return {
      token: null,
      appKey: ""
    };
  },
  methods: {
    loginSuccessCallback(token) {
      // this.ddAlert("callback",token)
      window.sessionStorage.setItem("token", token);
      window.localStorage.setItem("clearInfo", "");
      this.getAllDic();
      this.getSystem();
    },
    // 获取用户信息
    getUserInfo() {
      this.$store.dispatch("userInfoUsingPOSTS").then(res => {
        this.loadData();
      });
    },
    // 获取所有数据字典
    getAllDic() {
      this.API.dictionaryTree({ parentId: 0 }).then(res => {
        let tem = res.data;
        if (tem) {
          window.sessionStorage.setItem("allDic", JSON.stringify(tem));
          this.getUserInfo();
        }
      });
    },
    //获取系统配置
    getSystem() {
      let tem = { pageIndex: 1, pageSize: 10 };
      this.API.getSystemSettingPageList(tem).then(ret => {
        let tem = ret.data.records[0];
        window.sessionStorage.setItem("system", JSON.stringify(tem));
      });
    }
  }
};
